Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
How to reuse a "factory" method on a extendable class accordingly with the type?

I have a class: BaseResourceModel on my Angular application

export abstract class BaseResourceModel{
    id?: any;
    description?: string;
    name?: string;
}

And several other classes inheriting from it like this:

import { BaseResourceModel } from '@core/models/_base/base-resource.model';

export class CityModel extends BaseResourceModel{

    constructor(ufId?: number){
        super();
    }

    static factory(obj: any): CityModel{
        return Object.assign(new CityModel(), obj);
    }
}

I would like to know if there's a way or a proper way to put the static factory method on the BaseResourceModel, but specifying for each heir the type of assignment, like this:

export abstract class BaseResourceModel{
    id?: any;
    description?: string;
    name?: string;

    static factory(obj, class){
        //ex.: class parameter will get here like CityModel
        return Object.assign(new class(), obj);
    }

}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!